#include "Data.h"

const bool CData::Init(const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize)
{
    m_llSouProId = -1;
    m_llDesProId = -1;
	m_iQueueKey  = -1;
    m_bTopFlg = false;
	m_pszDataBuf = nullptr;
	m_iLen = 0;
    if (pvdPara != nullptr)
    {
		Parse(reinterpret_cast<char *>(const_cast<void *>(pvdPara)));        
    }
    else
    {
        m_strDataBuf = "";
    }
    m_bInitFlg = true;
    return m_bInitFlg;
}

const void CData::UnInit()
{
	if (m_pszDataBuf) delete[]m_pszDataBuf;
	return void();
}

const bool CData::TOP_FLAG()
{
    return m_bTopFlg;
}

void CData::SetTopFlag(const bool bTopFlag)
{
    m_bTopFlg = bTopFlag;
}

const char * CData::AsString(void * ptrPara /*= nullptr*/)
{
    return m_strDataBuf.length() == 0 ? m_pszDataBuf : m_strDataBuf.c_str();
}

const char * CData::AsString(const char * pszName, char ** pszBuf, unsigned long & ulLen)
{
	ulLen = m_iLen;
	(*pszBuf) = new char[ulLen];
	if (m_strDataBuf.length() == 0) memcpy((void *)pszBuf, (void *)m_strDataBuf.c_str(), ulLen);
	else memcpy((void *)pszBuf, (void *)m_pszDataBuf, ulLen);
	return (*pszBuf);
}

const bool CData::Parse(const char * pszData, int iLne)
{
	if (m_pszDataBuf)
	{
		delete m_pszDataBuf;
		m_pszDataBuf = nullptr;
		m_iLen = 0;
	}
	if (iLne == 0)
	{
		m_strDataBuf = pszData;		
		m_iLen = m_strDataBuf.length();
		m_pszDataBuf = const_cast<char *>(m_strDataBuf.c_str());
	}
	else
	{
		m_strDataBuf = "";
		m_iLen = iLne;
		m_pszDataBuf = new char[iLne];
		memcpy((void *)m_pszDataBuf, (void *)pszData, iLne);
	}    
    return true;
}

long long CData::SOURCE_PROCESS_ID()
{
    return m_llSouProId;
}

void CData::SetSourceProcessID(long long llProID)
{
    m_llSouProId = llProID;
}

long long CData::DESTINATION_PROCESS_ID()
{
    return m_llDesProId;
}

void CData::SetDestinationProcessID(long long llProID)
{
    m_llDesProId = llProID;
}

const char * CData::MSG_FLG()
{
    return m_strMsgFlg.c_str();
}

void CData::SetMsgFlg(const char * pszMsgFlg)
{
    m_strMsgFlg = pszMsgFlg;
}

const int CData::GetQueueKey()
{
	return m_iQueueKey;
}

const void CData::SetQueueKey(const int iQueueKey)
{
	m_iQueueKey = iQueueKey;
}

const int CData::DataSize()
{
	return m_iLen;
}
